﻿using Velocity4Net.App;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using Velocity4Net;

namespace Velocity4NetTest
{
    
    
    /// <summary>
    ///This is a test class for VelocityTest and is intended
    ///to contain all VelocityTest Unit Tests
    ///</summary>
    [TestClass()]
    public class VelocityTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Init
        ///</summary>
        [TestMethod()]
        public void InitTest()
        {

            StreamWriter sw = new StreamWriter(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "o.txt"));

            Dictionary<string, object> props = new Dictionary<string, object>(); // TODO: Initialize to an appropriate value
            string tplPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "templates");
            //props.Add("file.resource.loader.path", tplPath);
            props.Add("input.encoding", "UTF-8");
            props.Add("output.encoding", "UTF-8");
            //props.Add("velocimacro.library", "VM_global_library.vm");
            try
            {
                Velocity.Init(props);
                VelocityContext context = new VelocityContext();
                context.Put("test","Hello world!");
                Template template = Velocity.GetTemplate("t.txt");

                template.Merge(context, sw);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            sw.Flush();
            sw.Close();
        }
    }
}
